﻿$(document).ready(function () {

    btn_gift_detail();
    btn_gift_delete();
    btn_gift_change();
    btn_gift_add();

});

function btn_gift_detail() {
    $(".btn_gift_detail").die().live("click", function (e) {
        e.preventDefault();
        var thishandle = $(this);
        var giftid = $(this).parent().parent().find(".text_gift_id").text();

        var reg = new RegExp("(^|&)" + "username" + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        var username = null;
        if (r != null)
            username = unescape(r[2]);

        window.location.href = "/Gift/Gift_Detail?username=" + username + "&_gift_id=" + giftid;
    });
}

function btn_gift_delete() {
    $(".btn_gift_delete").die().live("click", function (e) {
        e.preventDefault();
        var thishandle = $(this);
        var _gift_id = $(this).parent().parent().find(".text_gift_id").text();
        $.ajax({
            url: "/GiftAction/Gift_Delete",
            type: "post",
            cache: false,
            data: {
                _gift_id: _gift_id
            },
            dataType: "json",
            success: function (msg) {
                if (msg.Result) {

                    thishandle.parent().parent().css("opacity", "0");
                    thishandle.parent().parent().delay(200).queue(function () {
                        $(this).remove();
                    });

                } else {
                    alert(msg.Message);
                }
            }
        });
    });
}

function btn_gift_add() {
    $("#btn_gift_add").die().live("click", function (e) {
        e.preventDefault();
        var _gift_id = $("#text_gift_id").val();
        var _gift_name = $("#text_gift_name").val();
        var _gift_credit = $("#text_gift_credit").val();
        var _gift_account = $("#text_gift_account").val();
        var _gift_src = $("#text_gift_src").val();
        var _gift_state = $("#text_gift_state").val();
        var _gift_type = $("#text_gift_type").val();
        var _gift_rangetime = $("#text_gift_rangetime").val();
        var _gift_sorttime = $("#text_gift_sorttime").val();
        var _gift_descript = $("#text_gift_descript").val();
        //        var str = _user_id + _user_name + _user_psw + _user_phone + _user_credit + _user_level;
        //        alert(str);
        if (_gift_id == "") {
            alert("礼品id不能为空");
            return;
        }
        if (_gift_name == "") {
            alert("礼品名用户名不能为空");
            return;
        }
        if (_gift_credit == "") {
            alert("积分要求不能为空");
            return;
        }
        if (_gift_account == "") {
            alert("礼品数量不能为空");
            return;
        }
        if (_gift_state == "") {
            alert("积分要求不能为空");
            return;
        }
        if (_gift_type == "") {
            alert("礼品类型不能为空");
            return;
        }
        if (_gift_rangetime == "") {
            alert("兑换时间不能为空");
            return;
        }
        if (_gift_sorttime == "") {
            alert("入库时间不能为空");
            return;
        }
        if (_gift_descript == "") {
            alert("礼品描述不能为空");
            return;
        }
        $.ajax({
            url: "/GiftAction/Gift_Add",
            type: "post",
            cache: false,
            data: {
                _gift_id: _gift_id,
                _gift_type: _gift_type,
               _gift_name: _gift_name,
               _gift_credit: _gift_credit,
               _gift_account: _gift_account,
               _gift_state: _gift_state,
               _gift_src: _gift_src,
               _gift_rangetime: _gift_rangetime,
               _gift_sorttime: _gift_sorttime,
               _gift_descript: _gift_descript
           },
           dataType: "json",
           success: function (msg) {
               if (msg.Result) {
                   alert("添加成功");
               } else {
                   alert("添加失败");
               }
           }
       });
    });


}

function btn_gift_change() {
    $("#btn_gift_change").die().live("click", function (e) {
        e.preventDefault();
        var _gift_id = $("#text_gift_id").val();
        var _gift_name = $("#text_gift_name").val();
        var _gift_credit = $("#text_gift_credit").val();
        var _gift_account = $("#text_gift_account").val();
        var _gift_src = $("#text_gift_src").val();
        var _gift_state = $("#text_gift_state").val();
        var _gift_type = $("#text_gift_type").val();
        var _gift_rangetime = $("#text_gift_rangetime").val();
        var _gift_sorttime = $("#text_gift_sorttime").val();
        var _gift_descript = $("#text_gift_descript").val();
        //        var str = _user_id + _user_name + _user_psw + _user_phone + _user_credit + _user_level;
        //        alert(str);
        if (_gift_id == "") {
            alert("礼品id不能为空");
            return;
        }
        if (_gift_name == "") {
            alert("礼品名用户名不能为空");
            return;
        }
        if (_gift_credit == "") {
            alert("积分要求不能为空");
            return;
        }
        if (_gift_account == "") {
            alert("礼品数量不能为空");
            return;
        }
        if (_gift_state == "") {
            alert("积分要求不能为空");
            return;
        }
        if (_gift_type == "") {
            alert("礼品类型不能为空");
            return;
        }
        if (_gift_rangetime == "") {
            alert("兑换时间不能为空");
            return;
        }
        if (_gift_sorttime == "") {
            alert("入库时间不能为空");
            return;
        }
        if (_gift_descript == "") {
            alert("礼品描述不能为空");
            return;
        }
        $.ajax({
            url: "/GiftAction/Gift_Change",
            type: "post",
            cache: false,
            data: {
                _gift_id: _gift_id,
                _gift_type: _gift_type,
                _gift_name: _gift_name,
                _gift_credit: _gift_credit,
                _gift_account: _gift_account,
                _gift_state: _gift_state,
                _gift_src: _gift_src,
                _gift_rangetime: _gift_rangetime,
                _gift_sorttime: _gift_sorttime,
                _gift_descript: _gift_descript
            },
            dataType: "json",
            success: function (msg) {
                if (msg.Result) {
                    alert(msg.Message);
                } else {
                    alert(msg.Message);
                }
            }
        });
    });

}




